-
Notifications
You must be signed in to change notification settings - Fork 355
api: Accept unknown "emojiset" values in initial snapshot #1983
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Let's make a new enum value |
df1e800 to
9382645
Compare
|
Thank you @chrisbobbe for the review, introduced a new enum value |
chrisbobbe
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Small comments below.
| 'presence_enabled': true, | ||
| }); | ||
|
|
||
| // Verify unknown emojiset defaults to Emojiset.unknow |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Emojiset.unknown
| final settings = UserSettings.fromJson({ | ||
| 'twenty_four_hour_time': true, | ||
| 'display_emoji_reaction_users': true, | ||
| 'emojiset': unknownValue, | ||
| 'presence_enabled': true, | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This .fromJson call will fail and need to be debugged each time we add a field to UserSettings.
Can you add a userSettings helper function in test/example_data.dart, on the pattern of similar helpers (like streamMessage or initialSnapshot), then I think this can just be
| final settings = UserSettings.fromJson({ | |
| 'twenty_four_hour_time': true, | |
| 'display_emoji_reaction_users': true, | |
| 'emojiset': unknownValue, | |
| 'presence_enabled': true, | |
| }); | |
| final json = eg.userSettings().toJson()..['emojiset'] = unknownValue; | |
| final settings = UserSettings.fromJson(json); |
1896109 to
59cd993
Compare
|
Thank you @chrisbobbe for the Suggestion, have pushed the changes. PTAL. |
chrisbobbe
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Just small comments below.
Also something I just noticed on this round: for the commit-message summary line, let's say
api: Accept unknown "emojiset" values in initial snapshot
test/example_data.dart
Outdated
| return UserSettings( | ||
| twentyFourHourTime: twentyFourHourTime ?? TwentyFourHourTimeMode.twentyFourHour, | ||
| displayEmojiReactionUsers: displayEmojiReactionUsers ?? true, | ||
| emojiset: emojiset ?? Emojiset.unknown , |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should aim to make the defaults boring and representative of real data, and I think Emojiset.google would be better for that than Emojiset.unknown.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also this helper can deduplicate some code in the initialSnapshot helper just below this.
Just below the userSettings function declaration, you can say
const _userSettings = userSettings;then in initialSnapshot in choosing arguments for the InitialSnapshot constructor, you can say:
userSettings: userSettings ?? _userSettings(),59cd993 to
7e79010
Compare
|
Thank you @chrisbobbe for noticing that, I've also changed the value of |
chrisbobbe
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! One nit below, and I'll mark this for Greg's review.
| } | ||
|
|
||
| const _userSettings = userSettings; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: remove blank line above const _userSettings = userSettings;, following the pattern of other helpers in this file
7e79010 to
7fc7cd8
Compare
|
Thank you @chrisbobbe for the review, the new changes had been pushed. PTAL @gnprice. |
gnprice
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @MritunjayTiwari14 for taking care of this, and thanks @chrisbobbe for the previous reviews! A few comments below.
| @JsonKey(unknownEnumValue: Emojiset.unknown) | ||
| Emojiset emojiset; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked at other references to Emojiset to see if we might need this elsewhere.
One is in events:
case UserSettingName.emojiset:
return Emojiset.fromRawString(value as String);It looks like the effect of that is that if the user's value for this setting gets changed to an unknown value, we'd still throw. Let's fix that so that it produces Emojiset.unknown, just like if the same unknown value is found in the initial snapshot.
|
|
||
| // Verify unknown emojiset defaults to Emojiset.unknown | ||
| check(settings.emojiset).equals(Emojiset.unknown); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment doesn't add anything that isn't said equally clearly by the code. So best to leave it out:
| // Verify unknown emojiset defaults to Emojiset.unknown | |
| check(settings.emojiset).equals(Emojiset.unknown); | |
| check(settings.emojiset).equals(Emojiset.unknown); |
| test('UserSettings.emojiset handles various unknown values', () { | ||
| final unknownValues = ['apple', 'microsoft', 'facebook', '']; | ||
| for (final unknownValue in unknownValues) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After the first of these, there's no useful information expressed by checking the next two — it's hard to imagine what sort of possible bug could be introduced in the future that would hit when the value were "microsoft" but not when it's "apple". So simplify the story by leaving them out:
| test('UserSettings.emojiset handles various unknown values', () { | |
| final unknownValues = ['apple', 'microsoft', 'facebook', '']; | |
| for (final unknownValue in unknownValues) { | |
| test('UserSettings.emojiset handles various unknown values', () { | |
| final unknownValues = ['apple', '']; | |
| for (final unknownValue in unknownValues) { |
(OTOH the empty string does add information, since that's an edge case where it's more conceivable that there could be a bug specifically affecting that case.)
Fixes #1981.